﻿//===========================[ 7 / 6 / 2011 LVI ]=============================
//				Copyright c Vitaly Lyaschenko <SkyChameleon@gmail.com>
// 								Header file
// Purpose: лог файл с потдержкой ANSI и UNICODE
//=============================================================================
#pragma once

#include "common.h"
#include "cFileManager.h"

class cwLogger
{
	// "стэк" всех записей лог файла
	static std::vector<std::wstring> logString;
	// путь к лог файлу
	static std::wstring logPath;
	static void writeFlush();

public:
	// UNICODE string
	static void create( const std::wstring &logfileName );

	static void writeINFO(const std::wstring &info);       // запись информации
	static void writeERROR(const std::wstring &info);      // запись ошибки
	static void writeFATAL_ERROR(const std::wstring &info);// запись критической ошибки

	// ANSI string
	static void create( const std::string &logfileName );
	static void writeINFO(const std::string &info);
	static void writeERROR(const std::string &info);
	static void writeFATAL_ERROR(const std::string &info);

	static std::wstring getLogPath() { return logPath; }
};

///////////////////////////////////////////////////////////////////////////
// Info: http://www.decompile.com/cpp/faq/file_and_line_error_string.htm
#define STRINGIFY(X) #X
#define TOSTRING(X) STRINGIFY(X)
#define AT __FILE__" : "TOSTRING(__LINE__)" : "__FUNCTION__

#define DebugInfo( STR,... ) { std::wfstream logFile( cwLogger::getLogPath(), std::ios::out | std::ios::app ); \
	logFile << to_wstring( " <+ dbg > "STR" : " AT ); \
	logFile.releaseSound(); } \

#define DebugError( STR,... ) { std::wfstream logFile( cwLogger::getLogPath(), std::ios::out | std::ios::app ); \
	logFile << to_wstring( " <! dbg > "STR" : " AT ); \
	logFile.releaseSound(); } \

#define DebugFatalError( STR,... ) { std::wfstream logFile( cwLogger::getLogPath(), std::ios::out | std::ios::app ); \
	logFile << to_wstring( " <X dbg > "STR" : " AT ); \
	logFile.releaseSound(); } \

#define DebugMessage( STR,... )  MessageBox( NULL, STR, "Message", MB_OK | MB_ICONINFORMATION )
///////////////////////////////////////////////////////////////////////////
